home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / programming / source / t3dlib_src_r43.lha / writetsipp.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-02-02  |  16.6 KB  |  619 lines

  1. /* writetsipp.c - dump the internal database to a TSIPP input file
  2.  *             - written by Glenn M. Lewis - 10/11/91
  3.  */
  4.  
  5. static char rcs_id[] = "$Id: writetsipp.c,v 1.1 1994/01/20 22:14:52 glewis Exp $";
  6.  
  7. #include <stdio.h>
  8. #include <ctype.h>
  9. #include "t3dlib.h"
  10. #ifdef __STDC__
  11. #include <stdlib.h>
  12. #include <strings.h>
  13. #include "writetsipp_protos.h"
  14. #endif
  15.  
  16. static void process_DESC();
  17. static void process_EXTR();
  18. static void process_INFO();
  19. static void process_OBJ();
  20.  
  21. /* Two-space tabs */
  22. #define TABSTOP "  "
  23.  
  24. static FILE *out;
  25. static char tab[133];
  26. static int num_OBJ, num_DESC, num_TOBJ;
  27. static int cur_level, cur_objnum;
  28. static int prntline;
  29.  
  30. static struct save_hier {
  31.     int objnum;
  32.     struct save_hier *next;
  33. } *root = 0;
  34. typedef struct save_hier HIER;
  35.  
  36. /* Here are a few necessary utilities */
  37.  
  38. static void indent()
  39. {
  40.     strcat(tab, TABSTOP);
  41. }
  42.  
  43. static void outdent()
  44. {
  45.     register int i = strlen(tab) - strlen(TABSTOP);
  46.     if (i<0) {
  47.         fprintf(stderr, "Whoa, Glenn!  You blew it!\n");
  48.         tab[0] = '\0';
  49.         return;
  50.     }
  51.     tab[i] = '\0';
  52. }
  53.  
  54. #define ROUNDIT(x) ((double)((long)((x)*1000.0+0.5-((x)<0.0)))/1000.0)
  55.  
  56. static void send_XYZ(f)            /* Print a common string */
  57. XYZ_st *f;
  58. {
  59.     fprintf(out, "{%.12g %.12g %.12g} ",
  60.         ROUNDIT(f->x), ROUNDIT(f->y), ROUNDIT(f->z));
  61. }
  62.  
  63. static void send_RGB(rgb)            /* Print a common string */
  64. RGB_st *rgb;
  65. {
  66.     fprintf(out, "{%.12g %.12g %.12g} ",
  67.         ROUNDIT(((double)rgb->r)/255.0),
  68.         ROUNDIT(((double)rgb->g)/255.0),
  69.         ROUNDIT(((double)rgb->b)/255.0));
  70. }
  71.  
  72. /********************/
  73. /* The MAIN section */
  74. /********************/
  75.  
  76. int write_TSIPP(world, file)
  77. WORLD *world;
  78. FILE *file;
  79. {
  80.     register OBJECT *o;
  81.  
  82.     if (!(out=file) || !world) return(0);    /* File not open */
  83.  
  84.     tab[0] = '\0';
  85.     num_OBJ = num_DESC = num_TOBJ = 0;
  86.  
  87.     fprintf(out, "## T3DLIB %s - Written by Glenn M. Lewis - %s\n\n",
  88.         REV, __DATE__);
  89.  
  90.     if (world->info) process_INFO(world->info);
  91.     for (o=world->object; o; o=o->next)
  92.         process_OBJ(o);
  93.     return(1);
  94. }
  95.  
  96. static void process_INFO(info)
  97. INFO *info;
  98. {
  99.     fprintf(out, "#%s INFO Begin\n", tab);
  100.     indent();
  101. /*
  102.     for (i=0; i<8; i++)
  103.         if (info->brsh[i][0])
  104.             fprintf(out, "%sBRSH[%d]=\"%s\"\n", tab, i, info->brsh[i]);
  105.  
  106.     for (i=0; i<8; i++)
  107.         if (info->stnc[i][0])
  108.             fprintf(out, "%sSTNC[%d]=\"%s\"\n", tab, i, info->stnc[i]);
  109.  
  110.     for (i=0; i<8; i++)
  111.         if (info->txtr[i][0])
  112.             fprintf(out, "%sTXTR[%d]=\"%s\"\n", tab, i, info->txtr[i]);
  113. */
  114.  
  115.     if (info->obsv) {
  116.         fprintf(out, "#%slookat(", tab); send_XYZ(&info->obsv->came);
  117.         fprintf(out, "#%s/* OBSV Rotate", tab); send_XYZ(&info->obsv->rota);
  118.         fprintf(out, "#%s   focaldist  %.12g */\n", tab, info->obsv->foca);
  119.         fprintf(out, "#%s)", tab);
  120.     }
  121.  
  122. /*    if (info->otrk[0]) fprintf(out, "%sOTRK \"%s\"\n", tab, info->otrk);    */
  123.  
  124. /*
  125.     if (info->ostr) {
  126.         if (info->ostr->path[0])
  127.             fprintf(out, "%sOSTR Path \"%s\"\n", tab, info->ostr->path);
  128.         fprintf(out, "%sOSTR Translate", tab); send_XYZ(&info->ostr->tran);
  129.         fprintf(out, "%sOSTR Rotate   ", tab); send_XYZ(&info->ostr->rota);
  130.         fprintf(out, "%sOSTR Scale    ", tab); send_XYZ(&info->ostr->scal);
  131.         i = info->ostr->info;
  132.         strin[0] = '\0';
  133.         if (i&(1<<0))  strcat(strin, " ABS_TRA");
  134.         if (i&(1<<1))  strcat(strin, " ABS_ROT");
  135.         if (i&(1<<2))  strcat(strin, " ABS_SCL");
  136.         if (i&(1<<4))  strcat(strin, " LOC_TRA");
  137.         if (i&(1<<5))  strcat(strin, " LOC_ROT");
  138.         if (i&(1<<6))  strcat(strin, " LOC_SCL");
  139.         if (i&(1<<8))  strcat(strin, " X_ALIGN");
  140.         if (i&(1<<9))  strcat(strin, " Y_ALIGN");
  141.         if (i&(1<<10)) strcat(strin, " Z_ALIGN");
  142.         if (i&(1<<12)) strcat(strin, " FOLLOW_ME");
  143.         fprintf(out, "%sOSTR Info%s\n", tab, strin);
  144.     }
  145. */
  146.  
  147.     if (info->fade) {
  148.         fprintf(out, "#%s/* FADE FadeAt %.12g*/\n", tab, info->fade->at);
  149.         fprintf(out, "#%s/* FADE FadeBy %.12g*/\n", tab, info->fade->by);
  150.         fprintf(out, "#%s/* FADE FadeTo", tab); send_RGB(&info->fade->to);
  151.         fprintf(out, "*/\n");
  152.     }
  153.  
  154.     if (info->skyc) {
  155.         fprintf(out, "#%s/* SKYX Horizon", tab); send_RGB(&info->skyc->hori);
  156.         fprintf(out, "*/\n");
  157.         fprintf(out, "#%s/* SKYC Zenith ", tab); send_RGB(&info->skyc->zeni);
  158.         fprintf(out, "*/\n");
  159.     }
  160.  
  161.     if (info->ambi)
  162.         { fprintf(out, "#%sbackground", tab); send_RGB(info->ambi); }
  163.  
  164. /*
  165.     if (info->glb0)
  166.         for (i=0; i<8; i++)
  167.             fprintf(out, "%sGLB0[%d]=%u\n", tab, i, info->glb0[i]);
  168. */
  169.  
  170.     outdent();
  171.     fprintf(out, "#%s/* End INFO */\n", tab);
  172. }
  173.  
  174. static void process_OBJ(obj)
  175. register OBJECT *obj;
  176. {
  177.     register HIER *p;
  178.     num_OBJ++;
  179.     fprintf(out, "#%s/* OBJ Begin \"Hierarchy %d\" */\n", tab, num_OBJ);
  180.     num_DESC = num_TOBJ = 0;        /* Reset counters */
  181.     cur_level = 0;
  182.     cur_objnum = 1;
  183.     prntline = 1;
  184.  
  185.     if (obj->extr) process_EXTR(obj->extr);
  186.     else process_DESC(obj);
  187.  
  188.     while (root) {                /* This should happen at most once. */
  189.         p = root->next;
  190.         free((char *)root);        /* Delete this from list */
  191.         root = p;
  192.         outdent();
  193.     }
  194.  
  195.     fprintf(out, "#%s/* End OBJ   \"Hierarchy %d\" */\n", tab, num_OBJ);
  196. }
  197.  
  198. static void process_TOBJ()
  199. {
  200.     register HIER *p;
  201.     if (num_DESC-num_TOBJ < cur_level) {    /* Pop old level off HIER */
  202.         cur_level--;
  203.         cur_objnum = root->objnum;
  204.         p = root->next;
  205.         free((char *)root);    /* Delete from list */
  206.         root = p;
  207.         outdent();    /* Pretty file formatting */
  208.     }
  209.     fprintf(out, "#%s}\n", tab);
  210.     fprintf(out, "#%s/* TOBJ       \"Object %d at level %d of hierarchy %d\" */\n",
  211.         tab, cur_objnum-1, num_DESC-num_TOBJ, num_OBJ);
  212.     num_TOBJ++;
  213.     prntline = 1;
  214. }
  215.  
  216. static void process_EXTR(extr)
  217. EXTR *extr;
  218. {
  219.     if (!prntline) fprintf(out, "\n");    /* Print one anyway */
  220.     indent();
  221.     num_DESC++;
  222.  
  223.     fprintf(out, "#%s/* EXTR Begin \"Object %d at level %d of hierarchy %d\" */\n",
  224.         tab, cur_objnum, num_DESC-num_TOBJ, num_OBJ);
  225. /*    fprintf(out, "%scomposite {\n", tab); */
  226.     indent();
  227.     fprintf(out, "#%s/* LOAD \"%s\" */\n", tab, extr->filename);
  228.     fprintf(out, "source %s\n", extr->filename);
  229.     fprintf(out, "#%stranslate(", tab); send_XYZ(&extr->mtrx.tran);
  230.     fprintf(out, ")\n#%sscale    (", tab); send_XYZ(&extr->mtrx.scal);
  231.     fprintf(out, "\n#%stransform {\n", tab);
  232.     indent();
  233.     fprintf(out, "#%s%.12g,%.12g,%.12g,",  tab,
  234.         extr->mtrx.rota1.x,
  235.         extr->mtrx.rota1.y,
  236.         extr->mtrx.rota1.z);
  237.     fprintf(out, "%s%.12g,%.12g,%.12g,",  tab,
  238.         extr->mtrx.rota2.x,
  239.         extr->mtrx.rota2.y,
  240.         extr->mtrx.rota2.z);
  241.     fprintf(out, "%s%.12g,%.12g,%.12g\n", tab,
  242.         extr->mtrx.rota3.x,
  243.         extr->mtrx.rota3.y,
  244.         extr->mtrx.rota3.z);
  245.     outdent();
  246.     fprintf(out, "#%s}\n", tab);
  247.  
  248.     outdent();
  249.     fprintf(out, "#%s}\n", tab);
  250.     fprintf(out, "#%s/* End EXTR   \"Object %d at level %d of hierarchy %d\" */\n",
  251.         tab, cur_objnum, num_DESC-num_TOBJ, num_OBJ);
  252.  
  253.     num_TOBJ++;
  254.     cur_objnum++;
  255.     outdent();
  256.     prntline = 1;
  257. }
  258.  
  259. void color_it(desc, i)
  260. DESC *desc;
  261. int i;
  262. {
  263.     double spec, r, g, b, opaq_r, opaq_g, opaq_b, c3;
  264.     double tmp1, tmp2, tmp3, intensity;
  265.     int spec_exp;
  266.  
  267.     intensity = 0.1;
  268.     if (desc->int1) {    /* Illuminated */
  269.         r = desc->int1->x*(1./255.);
  270.         g = desc->int1->y*(1./255.);
  271.         b = desc->int1->z*(1./255.);
  272.         intensity = (1./3.)*(r*r + g*g + b*b);
  273.     }
  274.  
  275.     if (desc->clst) {
  276.         r = desc->clst[i*3  ]*(1./255.);
  277.         g = desc->clst[i*3+1]*(1./255.);
  278.         b = desc->clst[i*3+2]*(1./255.);
  279.     } else if (desc->colr) {
  280.         r = desc->colr->r*(1./255.);
  281.         g = desc->colr->g*(1./255.);
  282.         b = desc->colr->b*(1./255.);
  283.     } else {
  284.         r = g = b = 1.0;
  285.     }
  286.  
  287.     if (desc->rlst) {
  288.         tmp1 = desc->rlst[i*3  ]*(1./255.);
  289.         tmp2 = desc->rlst[i*3+1]*(1./255.);
  290.         tmp3 = desc->rlst[i*3+2]*(1./255.);
  291.         spec = (1./3.)*(tmp1+tmp2+tmp3);    /* Average */
  292.         c3= (1./3.)*(tmp1*tmp1 + tmp3*tmp3 + tmp3*tmp3);
  293.         spec_exp = 1+((int)(c3*199.0));
  294.         c3 = 1.0 - c3;
  295.     } else if (desc->refl) {
  296.         tmp1 = desc->refl->r*(1./255.);
  297.         tmp2 = desc->refl->g*(1./255.);
  298.         tmp3 = desc->refl->b*(1./255.);
  299.         spec = (1./3.)*(tmp1+tmp2+tmp3);    /* Average */
  300.         c3= (1./3.)*(tmp1*tmp1 + tmp3*tmp3 + tmp3*tmp3);
  301.         spec_exp = 1+((int)(c3*199.0));
  302.         c3 = 1.0 - c3;
  303.     } else {
  304.         spec = 0.0;
  305.         c3   = 0.0;
  306.         spec_exp = 1;
  307.     }
  308.  
  309.     if (desc->tlst) {
  310.         opaq_r = 1.0 - (1./255.)*desc->tlst[i*3  ];
  311.         opaq_g = 1.0 - (1./255.)*desc->tlst[i*3+1];
  312.         opaq_b = 1.0 - (1./255.)*desc->tlst[i*3+2];
  313.     } else if (desc->tran) {
  314.         opaq_r = 1.0 - (1./255.)*desc->tran->r;
  315.         opaq_g = 1.0 - (1./255.)*desc->tran->g;
  316.         opaq_b = 1.0 - (1./255.)*desc->tran->b;
  317.     } else { opaq_r = opaq_g = opaq_b = 1.0; }
  318.  
  319.     if (desc->prp1 && !desc->prp1[6]) {    /* Flat shading */
  320.         fprintf(out, "SippObjectAddSurface $object [SippSurfaceCreate [SippShaderBasic %.12g %.12g %.12g {%.12g %.12g %.12g} {%.12g %.12g %.12g}]]\n",
  321.             ROUNDIT(intensity),
  322.             ROUNDIT(spec), ROUNDIT(c3), ROUNDIT(r), ROUNDIT(g), ROUNDIT(b),
  323.             ROUNDIT(opaq_r), ROUNDIT(opaq_g), ROUNDIT(opaq_b));
  324.     } else {    /* Phong shading */
  325.         fprintf(out, "SippObjectAddSurface $object [SippSurfaceCreate [SippShaderPhong %.12g 1.0 %.12g %d {%.12g %.12g %.12g} {%.12g %.12g %.12g}]]\n",
  326.             ROUNDIT(intensity),
  327.             ROUNDIT(spec), spec_exp, ROUNDIT(r), ROUNDIT(g), ROUNDIT(b),
  328.             ROUNDIT(opaq_r), ROUNDIT(opaq_g), ROUNDIT(opaq_b));
  329.     }
  330. }
  331.  
  332. static void process_DESC(object)
  333. OBJECT *object;
  334. {
  335.     register int i;
  336.     register HIER *p;
  337.     register OBJECT *obj;
  338.     register DESC *desc = object->desc;
  339.     register int p1, p2, p3;
  340.     int must_color_each_face = 0;
  341.  
  342.     num_DESC++;
  343.     if (num_DESC-num_TOBJ > cur_level) {    /* Push new level in HIER */
  344.         if (!prntline) fprintf(out, "\n");    /* Print one anyway */
  345.         if (!(p = (HIER*)malloc(sizeof(HIER)))) {
  346.             fprintf(stderr, "ERROR!  Out of memory.\n*** ABORT ***\n");
  347.             exit(20);
  348.         }
  349.         p->next = root;        /* Insert into list */
  350.         root = p;
  351.         root->objnum = cur_objnum;
  352.         cur_level++;
  353.         cur_objnum = 1;
  354.         indent();    /* Pretty file formatting */
  355.     }
  356.  
  357.     fprintf(out, "#%s/* DESC Begin \"Object %d at level %d of hierarchy %d\" */\n",
  358.         tab, cur_objnum, num_DESC-num_TOBJ, num_OBJ);
  359. /*    fprintf(out, "%sgrid 20 20 20\n", tab);    */
  360. /*    fprintf(out, "%scomposite {\n", tab); */
  361.     indent();
  362.  
  363.     if (desc->name[0]) fprintf(out, "#%s/* name \"%s\" */\n", tab, desc->name);
  364.  
  365.     if (desc->posi) {
  366.         fprintf(out, "#%stranslate(", tab);
  367.         send_XYZ(desc->posi);
  368.         fprintf(out, ")\n");
  369.     }
  370.  
  371. #if 0
  372.     if (desc->colr) {
  373.         fprintf(out, "#%sambient", tab);
  374.         send_RGB(desc->colr);
  375.         fprintf(out, "\n");
  376.     }
  377.  
  378.     if (desc->refl) {
  379.         fprintf(out, "#%s/* specular", tab);
  380.         send_RGB(desc->refl);
  381.         fprintf(out, "*/\n");
  382.     }
  383.  
  384.     if (desc->tran) { fprintf(out, "#%s/* TRAN", tab); send_RGB(desc->tran);
  385.         fprintf(out, "*/\n");
  386.     }
  387. #endif
  388.  
  389. #ifdef WRITETTDDD
  390.     if (desc->fcount) {
  391.         fprintf(out, "%sCLST Count %u\n", tab, i);
  392.         for (i=0; i<desc->fcount; i++) {
  393.             if (desc->colr) {
  394.                 if (desc->clst[i*3  ]==desc->colr->r &&
  395.                     desc->clst[i*3+1]==desc->colr->g &&
  396.                     desc->clst[i*3+2]==desc->colr->b) continue; /* Skip */
  397.             } else {
  398.                 if (desc->clst[i*3  ]==255 &&
  399.                     desc->clst[i*3+1]==255 &&
  400.                     desc->clst[i*3+2]==255) continue;    /* Skip this one */
  401.             }
  402.             fprintf(out, "%sCLST Color[%u]", tab, i);
  403.             send_RGB((RGB_st*)&desc->clst[i*3]);
  404.         }
  405.         fprintf(out, "%sRLST Count %u\n", tab, i);
  406.         for (i=0; i<desc->fcount; i++) {
  407.             if (desc->refl) {
  408.                 if (desc->rlst[i*3  ]==desc->refl->r &&
  409.                     desc->rlst[i*3+1]==desc->refl->g &&
  410.                     desc->rlst[i*3+2]==desc->refl->b) continue; /* Skip */
  411.             } else {
  412.                 if (desc->rlst[i*3  ]==0 &&
  413.                     desc->rlst[i*3+1]==0 &&
  414.                     desc->rlst[i*3+2]==0) continue;    /* Skip this one */
  415.             }
  416.             fprintf(out, "%sRLST Color[%u]", tab, i);
  417.             send_RGB((RGB_st*)&desc->rlst[i*3]);
  418.         }
  419.         fprintf(out, "%sTLST Count %u\n", tab, i);
  420.         for (i=0; i<desc->fcount; i++) {
  421.             if (desc->tran) {
  422.                 if (desc->tlst[i*3  ]==desc->tran->r &&
  423.                     desc->tlst[i*3+1]==desc->tran->g &&
  424.                     desc->tlst[i*3+2]==desc->tran->b) continue; /* Skip */
  425.             } else {
  426.                 if (desc->tlst[i*3  ]==0 &&
  427.                     desc->tlst[i*3+1]==0 &&
  428.                     desc->tlst[i*3+2]==0) continue;    /* Skip this one */
  429.             }
  430.             fprintf(out, "%sTLST Color[%u]", tab, i);
  431.             send_RGB((RGB_st*)&desc->tlst[i*3]);
  432.         }
  433.     }
  434. #endif
  435.  
  436.     if (desc->tpar) {
  437.         for (i=0; i<16; i++)
  438.             fprintf(out, "#%s/* TPAR[%u]=%.12g */\n", tab, i, desc->tpar[i]);
  439.     }
  440.  
  441.     if (desc->surf) {
  442.         for (i=0; i<5; i++)
  443.             fprintf(out, "#%s/* SURF[%u]=%d */\n", tab, i, desc->surf[i]);
  444.     }
  445.  
  446.     if (desc->mttr) {
  447.         fprintf(out, "#%s/* MTTR Type =%u */\n", tab, desc->mttr->type);
  448.         fprintf(out, "#%s/* MTTR Index=%.12g */\n", tab, (double)desc->mttr->indx);
  449.     }
  450.  
  451.     if (desc->spec) {
  452.         fprintf(out, "#%s/* SPEC Spec=%u */\n", tab, desc->spec[0]);
  453.         fprintf(out, "#%s/* SPEC Hard=%u */\n", tab, desc->spec[1]);
  454.     }
  455.  
  456.     if (desc->prp0) {
  457.         for (i=0; i<6; i++)
  458.             fprintf(out, "#%s/* PRP0[%u]=%u */\n", tab, i, desc->prp0[i]);
  459.     }
  460.  
  461.     if (desc->ints)
  462.         fprintf(out, "#%s/* INTS=%.12g */\n", tab, desc->ints);
  463.  
  464. #ifdef WRITETDDD
  465.     if (desc->stry) {
  466.         fprintf(out, "%sSTRY Path \"%s\"\n", tab, desc->stry->path);
  467.         fprintf(out, "%sSTRY Translate", tab); send_XYZ(&desc->stry->tran);
  468.         fprintf(out, "%sSTRY Rotate   ", tab); send_XYZ(&desc->stry->rota);
  469.         fprintf(out, "%sSTRY Scale    ", tab); send_XYZ(&desc->stry->scal);
  470.         i = desc->stry->info;
  471.         strin[0] = '\0';
  472.         if (i&(1<<0))  strcat(strin, " ABS_TRA");
  473.         if (i&(1<<1))  strcat(strin, " ABS_ROT");
  474.         if (i&(1<<2))  strcat(strin, " ABS_SCL");
  475.         if (i&(1<<4))  strcat(strin, " LOC_TRA");
  476.         if (i&(1<<5))  strcat(strin, " LOC_ROT");
  477.         if (i&(1<<6))  strcat(strin, " LOC_SCL");
  478.         if (i&(1<<8))  strcat(strin, " X_ALIGN");
  479.         if (i&(1<<9))  strcat(strin, " Y_ALIGN");
  480.         if (i&(1<<10)) strcat(strin, " Z_ALIGN");
  481.         if (i&(1<<12)) strcat(strin, " FOLLOW_ME");
  482.         fprintf(out, "%sSTRY Info%s\n", tab, strin);
  483.     }
  484. #endif
  485.  
  486.     if (desc->shap) {
  487.         fprintf(out, "#%s/* SHAP Shape = %u */\n", tab, desc->shap[0]);
  488.         if (desc->shap[0]==0 && !desc->shap[1]) {    /* Sphere */
  489.             fprintf(out, "#%ssphere {\n", tab);
  490.             indent();
  491.             fprintf(out, "#%scenter(", tab);
  492.             send_XYZ(desc->posi);
  493.             fprintf(out, ")\n#%sradius %.12g\n", tab, desc->size->x);
  494.             outdent();
  495.             fprintf(out, "#%s}\n", tab);
  496.             goto SKIP_REST;
  497.         }
  498.         fprintf(out, "#%s/* SHAP Lamp  = %u */\n", tab, desc->shap[1]);
  499.         if (desc->shap[1]==1 || desc->shap[1]==2) {
  500.             fprintf(out, "SippLightSourceCreate ");
  501.             if (desc->posi) send_XYZ(desc->posi); else fputs("{0 0 0} ", out);
  502.             if (desc->int1)
  503.                 fprintf(out, "{%.12g %.12g %.12g} ",
  504.                     ROUNDIT(desc->int1->x*(1./255.)),
  505.                     ROUNDIT(desc->int1->y*(1./255.)),
  506.                     ROUNDIT(desc->int1->z*(1./255.)));
  507.             else if (desc->colr)
  508.                 send_RGB(desc->colr);
  509.             else fputs("{1 1 1} ", out);
  510.  
  511.             if (desc->shap[1]==1)    /* Sunlight */
  512.                 fputs("DIRECTION\n", out);
  513.             else    /* Like a lamp */
  514.                 fputs("POINT\n", out);
  515.             goto SKIP_REST;
  516.         }
  517.     }
  518.  
  519. /*
  520.     if (desc->axis) {
  521.         fprintf(out, "%sAXIS XAxis", tab); send_XYZ(&desc->axis->xaxi);
  522.         fprintf(out, "%sAXIS YAxis", tab); send_XYZ(&desc->axis->yaxi);
  523.         fprintf(out, "%sAXIS ZAxis", tab); send_XYZ(&desc->axis->zaxi);
  524.     }
  525.  
  526.     if (desc->size)
  527.         { fprintf(out, "%sSIZE", tab); send_XYZ(desc->size); }
  528.  
  529.     if (desc->pcount) {
  530.         fprintf(out, "%sPNTS PCount %u\n", tab, desc->pcount);
  531.         for (i=0; i<desc->pcount; i++) {
  532.             fprintf(out, "%sPNTS Point[%d]", tab, i);
  533.             send_XYZ(&desc->pnts[i]);
  534.         }
  535.     }
  536.  
  537.     if (desc->ecount) {
  538.         fprintf(out, "%sEDGE ECount %u\n", tab, desc->ecount);
  539.         for (i=0; i<desc->ecount; i++) {
  540.             fprintf(out, "%sEDGE Edge[%d] %u %u\n", tab, i,
  541.                 desc->edge[i<<1], desc->edge[(i<<1)+1]);
  542.         }
  543.     }
  544. */
  545.  
  546.     if (desc->clst || desc->rlst || desc->tlst) {
  547.         for (i=1; i<desc->fcount; i++) {
  548.             if (desc->clst &&
  549.                (desc->clst[i*3  ]!=desc->clst[0] ||
  550.                 desc->clst[i*3+1]!=desc->clst[1] ||
  551.                 desc->clst[i*3+2]!=desc->clst[2])) {
  552.                     must_color_each_face = 1;
  553.                     break;
  554.             }
  555.             if (desc->rlst &&
  556.                (desc->rlst[i*3  ]!=desc->rlst[0] ||
  557.                 desc->rlst[i*3+1]!=desc->rlst[1] ||
  558.                 desc->rlst[i*3+2]!=desc->rlst[2])) {
  559.                     must_color_each_face = 1;
  560.                     break;
  561.             }
  562.             if (desc->tlst &&
  563.                (desc->tlst[i*3  ]!=desc->tlst[0] ||
  564.                 desc->tlst[i*3+1]!=desc->tlst[1] ||
  565.                 desc->tlst[i*3+2]!=desc->tlst[2])) {
  566.                     must_color_each_face = 1;
  567.                     break;
  568.             }
  569.         }
  570.     }
  571.  
  572.     if (desc->fcount && desc->ecount && desc->pcount) {
  573.         fprintf(out, "#%s/* FACE TCount %u */\n", tab, desc->fcount);
  574.         for (i=0; i<desc->fcount; i++) {
  575.         /* First check to make sure that this triangle is real */
  576.             p1 = desc->edge[(desc->face[i*3])<<1];
  577.             p2 = desc->edge[((desc->face[i*3])<<1)+1];
  578.             if (p1 == p2) continue;    /* How did *this* happen? */
  579.             p3 = desc->edge[(desc->face[i*3+2])<<1];
  580.             if (p1 == p3 || p2 == p3)
  581.                 p3 = desc->edge[((desc->face[i*3+2])<<1)+1];
  582.             if (p1 == p3 || p2 == p3) continue; /* How did *this* happen? */
  583.         /* Now check the actual points for equality */
  584.             if (bcmp(&desc->pnts[p1], &desc->pnts[p2], sizeof(XYZ_st))==0 ||
  585.                 bcmp(&desc->pnts[p1], &desc->pnts[p3], sizeof(XYZ_st))==0 ||
  586.                 bcmp(&desc->pnts[p2], &desc->pnts[p3], sizeof(XYZ_st))==0)
  587.                 continue;
  588.  
  589.             fprintf(out, "SippPolygonPush {");
  590.             send_XYZ(&desc->pnts[p1]);
  591.             send_XYZ(&desc->pnts[p2]);
  592.             send_XYZ(&desc->pnts[p3]);
  593.             fprintf(out, "}\n");
  594.             if (must_color_each_face)
  595.                 color_it(desc, i);
  596.         }
  597.  
  598.         if (!must_color_each_face)
  599.             color_it(desc, 0);
  600.     }
  601.  
  602. SKIP_REST:
  603.  
  604.     for (obj=object->child; obj; obj=obj->next) {
  605.         if (obj->extr) process_EXTR(obj->extr);
  606.         else process_DESC(obj);
  607.     }
  608.  
  609.     outdent();
  610.     fprintf(out, "#%s/* End DESC   \"Object %d at level %d of hierarchy %d\" */\n",
  611.         tab, cur_objnum, num_DESC-num_TOBJ, num_OBJ);
  612.  
  613.  
  614.     cur_objnum++;
  615.     prntline = 0;
  616.     process_TOBJ();
  617. }
  618.  
  619.